$(function () {
//submit comment method
    $('#CommentAddForm').on('click', '.sm_comment', function () {

        var parent = $(this).parent().parent().parent().parent();
        var id = $(parent).attr('attr');
        var name = $('#CommentWho').val();
        var comment = $('#CommentComment').val();
        if (name.length == 0) {
            window.alert("Bạn chưa nhập tên!");
            $('#CommentWho').focus();
        } else if (comment.length == 0) {
            window.alert("Bạn chưa nhập nội dung!");
            $('#CommentComment').focus();
        } else {
            $('.loadsm').fadeIn();
            $.post('comments/add', {orders_id: id, comment: comment, who: name}, function (res) {
                if (res == 'ok') {
                    $('.loadsm').fadeOut();
                    $('.oksm').fadeIn(1000).fadeOut();
                    var item = "<blockquote>";
                    item += "<p class='text-warning'>" + comment + "</p>";
                    item += "<footer>" + name + "</footer></blockquote>";

                    $(".item-cmt").append(item);
                    var number = parseInt($('p kbd').text()) + 1;
                    $('p kbd').text(number);
                    $('#CommentComment').val('');
                } else
                    window.alert("Comment loi!");
            });
        }
        return false;
    });
})